home *** CD-ROM | disk | FTP | other *** search
- package java.util;
-
- public class Timer {
- private TaskQueue queue;
- private TimerThread thread;
- private Object threadReaper;
- private static int nextSerialNumber = 0;
-
- private static synchronized int serialNumber() {
- return nextSerialNumber++;
- }
-
- public Timer() {
- this("Timer-" + serialNumber());
- }
-
- public Timer(boolean var1) {
- this("Timer-" + serialNumber(), var1);
- }
-
- public Timer(String var1) {
- this.queue = new TaskQueue();
- this.thread = new TimerThread(this.queue);
- this.threadReaper = new 1(this);
- this.thread.setName(var1);
- this.thread.start();
- }
-
- public Timer(String var1, boolean var2) {
- this.queue = new TaskQueue();
- this.thread = new TimerThread(this.queue);
- this.threadReaper = new 1(this);
- this.thread.setName(var1);
- this.thread.setDaemon(var2);
- this.thread.start();
- }
-
- public void schedule(TimerTask var1, long var2) {
- if (var2 < 0L) {
- throw new IllegalArgumentException("Negative delay.");
- } else {
- this.sched(var1, System.currentTimeMillis() + var2, 0L);
- }
- }
-
- public void schedule(TimerTask var1, Date var2) {
- this.sched(var1, var2.getTime(), 0L);
- }
-
- public void schedule(TimerTask var1, long var2, long var4) {
- if (var2 < 0L) {
- throw new IllegalArgumentException("Negative delay.");
- } else if (var4 <= 0L) {
- throw new IllegalArgumentException("Non-positive period.");
- } else {
- this.sched(var1, System.currentTimeMillis() + var2, -var4);
- }
- }
-
- public void schedule(TimerTask var1, Date var2, long var3) {
- if (var3 <= 0L) {
- throw new IllegalArgumentException("Non-positive period.");
- } else {
- this.sched(var1, var2.getTime(), -var3);
- }
- }
-
- public void scheduleAtFixedRate(TimerTask var1, long var2, long var4) {
- if (var2 < 0L) {
- throw new IllegalArgumentException("Negative delay.");
- } else if (var4 <= 0L) {
- throw new IllegalArgumentException("Non-positive period.");
- } else {
- this.sched(var1, System.currentTimeMillis() + var2, var4);
- }
- }
-
- public void scheduleAtFixedRate(TimerTask var1, Date var2, long var3) {
- if (var3 <= 0L) {
- throw new IllegalArgumentException("Non-positive period.");
- } else {
- this.sched(var1, var2.getTime(), var3);
- }
- }
-
- private void sched(TimerTask var1, long var2, long var4) {
- if (var2 < 0L) {
- throw new IllegalArgumentException("Illegal execution time.");
- } else {
- synchronized(this.queue) {
- if (!this.thread.newTasksMayBeScheduled) {
- throw new IllegalStateException("Timer already cancelled.");
- } else {
- synchronized(var1.lock) {
- if (var1.state != 0) {
- throw new IllegalStateException("Task already scheduled or cancelled");
- }
-
- var1.nextExecutionTime = var2;
- var1.period = var4;
- var1.state = 1;
- }
-
- this.queue.add(var1);
- if (this.queue.getMin() == var1) {
- this.queue.notify();
- }
-
- }
- }
- }
- }
-
- public void cancel() {
- synchronized(this.queue) {
- this.thread.newTasksMayBeScheduled = false;
- this.queue.clear();
- this.queue.notify();
- }
- }
-
- public int purge() {
- int var1 = 0;
- synchronized(this.queue) {
- for(int var3 = this.queue.size(); var3 > 0; --var3) {
- if (this.queue.get(var3).state == 3) {
- this.queue.quickRemove(var3);
- ++var1;
- }
- }
-
- if (var1 != 0) {
- this.queue.heapify();
- }
-
- return var1;
- }
- }
-
- // $FF: synthetic method
- static TaskQueue access$000(Timer var0) {
- return var0.queue;
- }
-
- // $FF: synthetic method
- static TimerThread access$100(Timer var0) {
- return var0.thread;
- }
- }
-